package com.csu.csumall.controller.frontend;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.csu.csumall.common.ItemStatus;
import com.csu.csumall.common.UniformResponse;
import com.csu.csumall.entity.Carousel;
import com.csu.csumall.service.ICarouselService;
import com.csu.csumall.service.ICartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.csu.csumall.common.Constant.ORIGIN;

@Slf4j
@RestController
@RequestMapping("/api/carousel")
@CrossOrigin(origins = ORIGIN)
public class CarouselController {

    private final ICarouselService carouselService;

    @Autowired
    public CarouselController(ICarouselService carouselService) {
        this.carouselService = carouselService;
    }

    @GetMapping(produces = "application/json")
    public UniformResponse get() {
        List<Carousel> carouselList = carouselService.list(
                new QueryWrapper<Carousel>().eq("status", ItemStatus.ENABLE.getValue()));
        carouselList.forEach(carousel -> {
            carousel.setCreateTime(null);
            carousel.setUpdateTime(null);
        });
        return UniformResponse.createForSuccess(carouselList);
    }
}
